package ar.uba.fi.RSACryptoFiuba.view;

import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.LayoutStyle.ComponentPlacement;

import ar.uba.fi.RSACryptoFiuba.model.decrypt.RSADecryptMessage;
import ar.uba.fi.RSACryptoFiuba.model.encrypt.RSAEncryptMessage;
import ar.uba.fi.RSACryptoFiuba.model.keygeneration.RSAKeyGenerationMessage;
import ar.uba.fi.RSACryptoFiuba.view.commons.TitlePanel;
import ar.uba.fi.RSACryptoFiuba.view.decrypt.DecryptLearningPanel;
import ar.uba.fi.RSACryptoFiuba.view.encrypt.EncryptLearningPanel;
import ar.uba.fi.RSACryptoFiuba.view.keygeneration.GenerateKeysLearningPanel;

@SuppressWarnings("serial")                          
public class LearningPanel extends JPanel {
	
	private JTabbedPane tabbedPane;
	private JPanel generateKeysTab;
    private JPanel decryptTab;
    private JPanel encryptTab;
    
    private RSAKeyGenerationMessage keyGenerationMessage;
    private RSAEncryptMessage encryptMessage;
    private RSADecryptMessage decryptMessage;
   	
    public LearningPanel(ActionListener modeActionListener) {
        initComponents(modeActionListener);
    }

    private void initComponents(ActionListener modeActionListener) {
    	
    	//Title Panel
    	JPanel titlePanel = new TitlePanel("Modo Aprendizaje");
    	  
        //Tabs
        tabbedPane = new JTabbedPane();
        
        keyGenerationMessage = new RSAKeyGenerationMessage();
        encryptMessage = new RSAEncryptMessage();
        decryptMessage = new RSADecryptMessage();
        
        generateKeysTab = new GenerateKeysLearningPanel(modeActionListener, keyGenerationMessage);
        tabbedPane.addTab("Generar Claves", generateKeysTab);
        
        encryptTab = new EncryptLearningPanel(modeActionListener, keyGenerationMessage, encryptMessage, decryptMessage);
        tabbedPane.addTab("Encriptar", encryptTab);

        decryptTab = new DecryptLearningPanel(modeActionListener, keyGenerationMessage, encryptMessage, decryptMessage);
        tabbedPane.addTab("Desencriptar", decryptTab);

        GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addComponent(titlePanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(tabbedPane)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titlePanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(tabbedPane, GroupLayout.PREFERRED_SIZE, 373, GroupLayout.PREFERRED_SIZE))
        );
    }                         
                                    
}     
        
